# ~*~ coding: utf-8 ~*~
import os
from apps.config import ConfigManager
from apps.config import PROJECT_DIR

CONFIG = ConfigManager.load_user_config()

# celery 默认配置
CELERY_BROKER_URL = 'redis://:{}@{}:{}/{}'.format(CONFIG.get('REDIS_PASSWORD'), CONFIG.get('REDIS_HOST'), CONFIG.get('REDIS_PORT'),  CONFIG.get('REDIS_DB'))
CELERY_RESULT_BACKEND = 'redis://:{}@{}:{}/{}'.format(CONFIG.get('REDIS_PASSWORD'), CONFIG.get('REDIS_HOST'), CONFIG.get('REDIS_PORT'),  CONFIG.get('REDIS_DB'))
CELERY_LOG_DIR = os.path.join(PROJECT_DIR, 'data', 'celery')
CELERY_LOG_BROKER_URL = ''
CELERY_TASK_SERIALIZER = 'pickle'
CELERY_RESULT_SERIALIZER = 'pickle'
CELERY_ACCEPT_CONTENT = ['json', 'pickle']
CELERY_RESULT_EXPIRES = 3600
CELERY_WORKER_TASK_LOG_FORMAT = '%(task_id)s %(task_name)s %(message)s'
CELERY_ENABLE_UTC = True
CELERY_TIMEZONE = 'Asia/Shanghai'
BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 86405}
CELERYD_TASK_SOFT_TIME_LIMIT = 86400

# 修改celery beat 默认的调度器为 RedBeatScheduler
REDBEAT_REDIS_URL = 'redis://:{}@{}:{}/{}'.format(CONFIG.get('REDIS_PASSWORD'), CONFIG.get('REDIS_HOST'), CONFIG.get('REDIS_PORT'), CONFIG.get('REDIS_DB'))
REDBEAT_KEY_PREFIX = 'beat:'
REDBEAT_LOCK_KEY = None
